package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.operation.domain.MiniBanner;
import com.yfp.operation.domain.dto.*;
import com.yfp.operation.domain.vo.MiniBannerListVO;
import com.yfp.operation.domain.vo.MiniBannerVO;
import com.yfp.operation.service.MiniBannerService;
import com.yfp.operation.domain.dto.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/miniBanner")
@Tag(name = "广告管理-小程序广告")
public class MiniBannerController extends BaseController {

    @Resource
    private MiniBannerService miniBannerService;

    @PostMapping("/getMiniBannersList")
    @Operation(summary = "获取小程序广告列表")
    public R<List<MiniBannerListVO>> getMiniBannersList(@RequestBody MiniBannersListDTO miniBannersListDTO) {
        List<MiniBannerListVO> miniBanners = miniBannerService.getMiniBannersList(miniBannersListDTO.getName(), miniBannersListDTO.getCityName());
        return R.ok(miniBanners);
    }


    @GetMapping("/getMiniBanner")
    @Operation(summary = "获取小程序弹窗列表")
    public TableDataInfo<MiniBanner> getMiniBanner(MiniBannersListDTO miniBannersListDTO){
        startPage();
        List<MiniBanner> list = miniBannerService.getMiniBanner(miniBannersListDTO);
        return getDataTable(list);
    }



    @GetMapping("/{id}")
    @Operation(summary = "获取小程序广告详情")
    public R<MiniBannerVO> getMiniBannerById(@Schema(description = "主键") @PathVariable Long id) {
        MiniBannerVO miniBanner = miniBannerService.getMiniBannerById(id);
        return R.ok(miniBanner);
    }

    @PostMapping
    @Operation(summary = "创建小程序广告")
    public R<Void> createMiniBanner(@RequestBody MiniBannerDTO miniBannerDTO) {
        miniBannerService.createMiniBanner(miniBannerDTO);
        return R.ok();
    }

    @PutMapping
    @Operation(summary = "更新小程序广告")
    public R<Void> updateMiniBanner(@RequestBody MiniBannerDTO miniBannerDTO) {
        miniBannerService.updateMiniBanner(miniBannerDTO);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除小程序广告")
    public R<Void> deleteMiniBanner(@Schema(description = "主键") @PathVariable Long id) {
        miniBannerService.deleteMiniBanner(id);
        return R.ok();
    }


    @GetMapping("/check")
    @Operation(summary = "校验是否存在小程序弹窗广告")
    public R<Boolean> checkMiniBanner(@RequestParam("cityName") String cityName) {
        boolean exist = miniBannerService.checkMiniBanner(cityName);
        return R.ok(exist);
    }

    @GetMapping("/marketing/list")
    @Operation(summary = "获取活动列表")
    public TableDataInfo<MarketingDTO> getMarketingList(MarketingNoActivityDTO marketingNoActivityDTO) {
        startPage();
        List<MarketingDTO> marketingList = miniBannerService.getMarketingList(marketingNoActivityDTO);
        return getDataTable(marketingList);
    }



    @PostMapping("/sort")
    @Operation(summary = "小程序广告排序")
    public R<Void> sort(@RequestBody BannerSortDTO bannerSortDTO){
        miniBannerService.sort(bannerSortDTO);
        return R.ok();
    }



}
